var baseurl = "http://flashq.tevobiz.com/api"; 
var baseDomain = "http://flashq.tevobiz.com"; 
var baseSocket="ws://msg.tevobiz.com:803/ws";
const API = {
  baseUrl:baseurl,
  baseDomain:baseDomain, 
  baseSocket:baseSocket,
  request: function(method, url, data, contenType) {
    let p = {
      XToken: '',
      DeviceId: '',
	  liberSession:'',
      ContentType: 'application/json',
	  liberSessionUniapp:''
    };
    var XToken = uni.getStorageSync('X-Token');
    if (XToken) {
      p.XToken = XToken;
	  
    }
	var DeviceId = uni.getStorageSync('DeviceId');
	console.log(DeviceId,'设备uu唯一标识id')
	if(DeviceId){
	  p.DeviceId=DeviceId
	}
    var XUser = uni.getStorageSync('X-User');
    if (XUser) {
      p.XUser = XUser;
    }
    if (contenType) {
      p.ContentType = contenType;
    }
	var liberSession=uni.getStorageSync("liber_session")
		console.log(liberSession,'设备websoketId')
	if(liberSession){   //websoket标识
		p.liberSession=liberSession
	}
	var liberSessionUniapp=uni.getStorageSync("clientid")
	console.log(liberSessionUniapp,'推送标识标识id')
	if(liberSessionUniapp){   //推送标识标识
		p.liberSessionUniapp=liberSessionUniapp
	}else{
		// #ifdef APP-PLUS
		p.liberSessionUniapp=plus.push.getClientInfo().clientid
		uni.setStorageSync("clientid",plus.push.getClientInfo().clientid)
		// #endif
	}
	
    var herders = {
      'AccessToken': p.XToken,
      'Content-Type': p.ContentType,
      'DeviceId': p.DeviceId,
	  'liberSession':p.liberSession,
	  'liberSessionUniapp':p.liberSessionUniapp
    };
    return new Promise((resolve, reject) => {
      uni.request({
        url: baseurl + url,
        header: herders,
        data: data,
        method: method,
        success: function(res) {
		  if(res.data.ErrorCode=="AccessDenied"){
                      // 将用户的Token在本地数据储存里面去移除
				uni.removeStorageSync("X-Token")
				uni.removeStorageSync("X-Headimg")
				uni.removeStorageSync("X-userName")
				uni.removeStorageSync("X-userPhone")
				uni.removeStorageSync("X-userId")
				uni.removeStorageSync("X-realname")  
				uni.removeStorageSync("X-gender")
				uni.removeStorageSync("X-card")
				uni.removeStorageSync("X-regionname")
				uni.removeStorageSync("X-regioncode")
		  }
		  if(url=="/v1/flash/session"){
			  resolve(res)
		  }
          resolve(res.data)
        },
        fail: function(err) {
          reject(err)
        }
      })
    });
  },
  GET: function(url,data) {
    return this.request('GET', url,data);
  },
  POST: function(url, data, contenType) {
    return this.request('POST', url, data, contenType);
  },
  PUT: function(url, data, contenType) {
    return this.request('PUT', url, data, contenType);
  },
  DELETE: function(url, data) {
    return this.request('DELETE', url, data);
  },
  baseurl: baseurl
};
module.exports = API;